﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bierdopje.API
{
    /// <summary>
    /// This is an representation of the Episode structure returned by the
    /// bierdopje API
    /// </summary>
    public class ApiEpisode
    {
        private int m_ID;

        public int ID
        {
            get { return m_ID; }
            set { m_ID = value; }
        }
        private int m_TVDBID;

        public int TVDBID
        {
            get { return m_TVDBID; }
            set { m_TVDBID = value; }
        }
        private string m_Title;

        public string Title
        {
            get { return m_Title; }
            set { m_Title = value; }
        }
        private string m_Link;

        public string Link
        {
            get { return m_Link; }
            set { m_Link = value; }
        }
        private int m_Season;

        public int Season
        {
            get { return m_Season; }
            set { m_Season = value; }
        }
        private int m_Episode;

        public int Episode
        {
            get { return m_Episode; }
            set { m_Episode = value; }
        }
        private int m_EpisodeNumber;

        public int EpisodeNumber
        {
            get { return m_EpisodeNumber; }
            set { m_EpisodeNumber = value; }
        }
        private bool m_WorkInProgress;

        public bool WorkInProgress
        {
            get { return m_WorkInProgress; }
            set { m_WorkInProgress = value; }
        }
        private Decimal m_WorkInProgressPercentage;

        public Decimal WorkInProgressPercentage
        {
            get { return m_WorkInProgressPercentage; }
            set { m_WorkInProgressPercentage = value; }
        }
        private string m_WorkInProgressUser;

        public string WorkInProgressUser
        {
            get { return m_WorkInProgressUser; }
            set { m_WorkInProgressUser = value; }
        }
        private Decimal m_Score;

        public Decimal Score
        {
            get { return m_Score; }
            set { m_Score = value; }
        }
        private int m_Votes;

        public int Votes
        {
            get { return m_Votes; }
            set { m_Votes = value; }
        }
        private DateTime m_AirDate;

        public DateTime AirDate
        {
            get { return m_AirDate; }
            set { m_AirDate = value; }
        }

        public TimeSpan EpisodeAge
        {
            get { return DateTime.Now - AirDate; }
        }

        private string m_FormattedEpisodeString;

        public string FormattedEpisodeString
        {
            get { return m_FormattedEpisodeString; }
            set { m_FormattedEpisodeString = value; }
        }
        private bool m_SpecialEpisode;

        public bool SpecialEpisode
        {
            get { return m_SpecialEpisode; }
            set { m_SpecialEpisode = value; }
        }
        private bool m_NLSubPresent;

        public bool NLSubPresent
        {
            get { return m_NLSubPresent; }
            set { m_NLSubPresent = value; }
        }
        private bool m_ENGSubPresent;

        public bool ENGSubPresent
        {
            get { return m_ENGSubPresent; }
            set { m_ENGSubPresent = value; }
        }
        private string m_Summary;

        public string Summary
        {
            get { return m_Summary; }
            set { m_Summary = value; }
        }

        /// <summary>
        /// Gets all Dutch subtitles
        /// </summary>
        /// <returns>List of ApiSub objects</returns>
        public List<ApiSub> GetNLSubs()
        {
            if (NLSubPresent)
            {
                return m_ApiLibrary.GetAllSubsForEpisode(this.ID, "nl");
            }
            else
            {
                throw new EApiSubsNotPresent();
            }
        }

        /// <summary>
        /// Gets all English subtitles
        /// </summary>
        /// <returns>List of ApiSub objects</returns>
        public List<ApiSub> GetENGSubs()
        {
            if (ENGSubPresent)
            {
                return m_ApiLibrary.GetAllSubsForEpisode(this.ID, "en");
            }
            else
            {
                throw new EApiSubsNotPresent();
            }
        }

        /// <summary>
        /// Hide the default constructor
        /// </summary>
        private ApiEpisode()
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Make sure the object is only created by the API, need for refrence issues
        /// </summary>
        /// <param name="apiLibrary">Reference to the parent library</param>
        internal ApiEpisode(ApiLibrary apiLibrary)
        {
            m_ApiLibrary = apiLibrary;    
        }

        private ApiLibrary m_ApiLibrary;
    }
}
